<?php include './include/conf.php'; 

if(!empty($_POST['identifiant']) && !empty($_POST['mdp'])) {
	$selectuser = $pdo->prepare('select *,concat(prenom,".",nom) as identifiant from adherent where CONCAT(prenom,".",nom) = ? and mdp = ? ');
	$selectuser->execute(array($_POST['identifiant'],crypt($_POST['mdp'],$_POST['identifiant'])));
	if($selectuser->rowcount() == 0){
		$_SESSION['erreur'] = 'Identifiants invalides';
		header('Location: connexion.php');
	}else{
		$user = $selectuser->fetch();
		if($user->est_archive == 1){
			$_SESSION['erreur'] = "Votre compte n'est plus valide";
			header('Location: connexion.php');			
		}elseif($user->est_archive == 1){
			$_SESSION['erreur'] = "Votre compte n'a pas encore été validé";
			header('Location: connexion.php');
		}else{
			$_SESSION['identifiant'] = $user->identifiant;
			$_SESSION['webmaster'] = $user->est_webmaster;
			if($user->est_webmaster == 1){
				header('Location: notification.php');
			}else{
				header('Location: informations.php');
			}
		}
	}
}else{
	if($_POST['identifiant'] == "" && $_POST['mdp'] == ""){
		$_SESSION['erreur'] = "Veuillez saisir votre identifiant et votre mot de passe";
	}else{
		$_SESSION["erreur"] = $_POST['identifiant'] == ""? "Veuillez saisir votre identifiant":"";
		$_SESSION["erreur"] = $_POST['mdp'] == ""? "Veuillez saisir votre mot de passe":"";
	}
	$_SESSION['identifiant'] = $_POST['identifiant'];
	header('Location: connexion.php');
}

//$select = $pdo->prepare('select * from adherent');
//$select->execute();
//while($user = $select->fetch())
?>